package com.atguigu.cloud.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.atguigu.cloud.entities.Pay;
import com.atguigu.cloud.resp.ResultData;
import com.atguigu.cloud.service.PayService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Enumeration;

@RestController
public class PayGateWayController {
    @Resource
    private PayService payService;

    @GetMapping("/pay/gateway/get/{id}")
    public ResultData<Pay> getById(@PathVariable("id") Integer id){
        
        return ResultData.success(payService.getById(id));
    }
    @GetMapping("/pay/gateway/get/info")
    public ResultData<String> getInfo(){
        return ResultData.success("gateway info test "+ IdUtil.simpleUUID());
    }

    @GetMapping("/pay/gateway/filter")
    public ResultData<String> getFilter(HttpServletRequest httpServletRequest){
        String result="";
        Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String headerName = headerNames.nextElement();
            String headerValue = httpServletRequest.getHeader(headerName);
            System.out.println("请求头名"+headerName+"\t\t\t"+"请求头值"+headerValue);
            if(headerName.equalsIgnoreCase("X-Request-atguigu1")||
            headerName.equalsIgnoreCase("X-Request-atguigu2")){
                result=result+headerName+"\t"+headerValue+" ";
            }
        }

        System.out.println("=============================================");
        String customerId = httpServletRequest.getParameter("customerId");
        System.out.println("request Parameter customerId: "+customerId);

        String customerName = httpServletRequest.getParameter("customerName");
        System.out.println("request Parameter customerName: "+customerName);
        System.out.println("=============================================");

        return ResultData.success("gateWayFilter 过滤器test："+result+"\t"+ DateUtil.now());
    }
}
